package com.aiton.bamin.bamindaijiadrier.activity;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Toast;

import com.aiton.administrator.shane_library.shane.utils.IsQQorWeiXinAvilible;
import com.aiton.administrator.shane_library.shane.widget.TwoBtnDialog;
import com.aiton.bamin.bamindaijiadrier.R;
import com.aiton.bamin.bamindaijiadrier.constant.Constant;

public class KefuActivity extends ZjbBaseActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kefu);
        init();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void setListeners() {
        findViewById(R.id.rela_qq).setOnClickListener(this);
        findViewById(R.id.rela_phone).setOnClickListener(this);
        findViewById(R.id.imageView_back).setOnClickListener(this);

    }

    @Override
    protected void initSP() {

    }

    @Override
    protected void initIntent() {

    }

    @Override
    protected void findID() {

    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.imageView_back:
                finishTo();
                break;
            case R.id.rela_qq:
                boolean qqClientAvailable = IsQQorWeiXinAvilible.isQQClientAvailable(this);
                if (qqClientAvailable) {
                    String url = "mqqwpa://im/chat?chat_type=wpa&uin=3464910568";
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                } else {
                    Toast.makeText(this, "QQ未安装", Toast.LENGTH_SHORT).show();
                }
                break;

            case R.id.rela_phone:
                if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)
                        != PackageManager.PERMISSION_GRANTED) {
                    //申请WRITE_EXTERNAL_STORAGE权限
                    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE},
                            Constant.PERMISSION.CALL_PHONE);
                } else {
                    final TwoBtnDialog twoBtnDialog = new TwoBtnDialog(this,"是否直接拨打客服电话400-0593-330","是" ,"否" );
                    twoBtnDialog.setClicklistener(new TwoBtnDialog.ClickListenerInterface() {
                        @Override
                        public void doConfirm() {
                            twoBtnDialog.dismiss();
                            //用intent启动拨打电话
                            Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "4000593330"));
                            startActivityTo(intent);
                        }
                        @Override
                        public void doCancel() {
                            twoBtnDialog.dismiss();

                        }
                    });
                    twoBtnDialog.show();
                }
                break;
        }
    }
}
